package com.alibaba.dingtalk.openapi.demo.utils;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class DbconnSqlserver {
	private Connection conn;
	public Connection getConnection() throws SQLException{
		try{
			Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");//net.sourceforge.jtds.jdbc.Driver
			conn=DriverManager.getConnection("jdbc:sqlserver://172.16.0.2:1433;databasename=lm","sa","Xaland123");
		}
		catch(ClassNotFoundException e){
			e.printStackTrace();
		}
		return conn;
	}
	public void closeAll(Connection conn,Statement stat,ResultSet rs){
	if(rs!=null){
		try{rs.close();}
		catch(SQLException e){
			e.printStackTrace();
		}finally{
			if(stat!=null){
				try{stat.close();}
				catch(SQLException e){
					e.printStackTrace();
			}finally{
				if(conn!=null){
					try{
						conn.close();
					}
					catch(SQLException e){
						e.printStackTrace();
				}
					}
			}
		}
	}
	}
	}
}
